package experimentForth;

import java.util.HashMap;

class FileSystem {
    //主目录[MFD]
    private HashMap<String, UserFileDirectory> mfd;

    // 构造函数，初始化文件系统
    // 设计10个用户的文件系统，每次用户可保存10个文件
    public FileSystem() {
        this.mfd = new HashMap<>();
        for (int i = 1; i <= 10; i++) {
            mfd.put("User" + i, new UserFileDirectory());
        }
    }

    // 创建文件
    public void create(String username, String filename, String protectionCode) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.create(filename, protectionCode);
        } else {
            System.out.println("User does not exist.");
        }
    }

    // 删除文件
    public void delete(String username, String filename) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.delete(filename);
        } else {
            System.out.println("User does not exist.");
        }
    }

    // ...
    // 打开文件
    public void open(String username, String filename) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.open(filename);
        } else {
            System.out.println("User does not exist.");
        }
    }

    // 关闭文件
    public void close(String username, String filename) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.close(filename);
        } else {
            System.out.println("User does not exist.");
        }
    }

    // 读取文件
    public void read(String username, String filename) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.read(filename);
        } else {
            System.out.println("User does not exist.");
        }
    }

    // 写入文件
    public void write(String username, String filename, String content) {
        UserFileDirectory ufd = mfd.get(username);
        if (ufd != null) {
            ufd.write(filename, content);
        } else {
            System.out.println("User does not exist.");
        }
    }
}